package org.mixed.config;

import org.mixed.core.resource.Resource;
import org.mixed.core.resource.ResourceAdapter;
import org.mixed.core.resource.storage.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

@Configuration
public class MixResourceConfiguration {
    @Autowired
    MixProperties properties;

    @Bean
    @ConditionalOnProperty(prefix = "mix", name = "resource.type", havingValue = "file", matchIfMissing = true)
    public Resource fileResource() throws IOException {
        MixStorage storage = properties.getStorage();
        return ResourceAdapter.getResource(storage.getLocation(), false);
    }

    @Bean
    public ApiInfoResourceStorage apiInfoResourceStorage() {
        return new ApiInfoResourceStorage(properties.getPrefix());
    }

    @Bean
    public FunctionInfoResourceStorage functionInfoResourceStorage() {
        return new FunctionInfoResourceStorage();
    }

    @Bean
    public DataSourceInfoResourceStorage dataSourceInfoResourceStorage() {
        return new DataSourceInfoResourceStorage();
    }

    @Bean
    public ComponentInfoResourceStorage componentInfoMagicResourceStorage() {
        return new ComponentInfoResourceStorage();
    }

    @Bean
    public TaskInfoResourceStorage taskInfoMagicResourceStorage() {
        return new TaskInfoResourceStorage();
    }

}
